package 面试题03_1.原地交换实现;

/**
 * @Author ：xu_xiaofeng.
 * @Date ：Created in 10:16 2021/2/3
 * @Description：
 */
class Solution {
    public int findRepeatNumber(int[] nums) {
        int nums_count = nums.length;

        int result = -1;
        for (int num : nums) {
            if (num < 0 || num > nums_count) {
                return result;
            }
        }

        for (int i = 0; i < nums_count; i++) {
            // 如果当前元素值等于下标，则继续扫描下一个数值
            if (nums[i] == i) {
                continue;
            } else if (nums[i] == nums[nums[i]]) {
                // 如果它和第对应下标的值相等，则说明该值重复了
                return nums[i];
            } else {
                int j = nums[i];
                int temp = nums[j];
                nums[j] = nums[i];
                nums[i] = temp;
            }
        }
        return result;
    }


}
